import com.qzw.common.util.ReflectUtils;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;

/**
 * @author ：quziwei
 * @date ：Created in 2020/6/1 2:54 下午
 * @description：反射测试启动类
 */
public class test {

    @Test
    public void entity2model(){
        Entity entity = new Entity();
        entity.setId(1);
        entity.setAge(15);
        entity.setName("张三");
        entity.setSex("男");
        Model model = new Model();
        ReflectUtils<Model,Entity> reflectUtils = new ReflectUtils<>();
        try {
            System.out.println(reflectUtils.entity2model(entity,model));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }


    @Test
    public void model2Entity() throws InvocationTargetException, NoSuchMethodException, NoSuchFieldException, InstantiationException, IllegalAccessException {
        Model model = new Model();
        model.setId(1);
        model.setAge(15);
        model.setName("张三");
        model.setSex("男");

        Entity entity = new Entity();
        ReflectUtils<Model,Entity> reflectUtils = new ReflectUtils<>();
        System.out.println(reflectUtils.model2entity(model,entity));
    }
}
